<?php
	
	class Log
	{
		private static $ErrorLog = Array();
		private static $filename = "ErrorLog.txt";
		
		// Create a message and add it to the array.
		public static function LogMessage($ErrorMessage)
		{
			$ErrorMessage .= " : " . Log::SetTime();
			
			Log::$ErrorLog[] = $ErrorMessage;
		}
		
		// Create a Error and add it to both the array and a textfile.
		public static function LogError($ErrorMessage)
		{
			// Add the error to the array.
			$temp = '<font color="red">' . $ErrorMessage . " : " . Log::SetTime() . '</font>';
			
			Log::$ErrorLog[] = $temp;
			
			
			// Add the error to the end of the textfile, if the file dosen't exist create it.
			$ErrorMessage .= " : " . Log::SetTime();
			
			Log::SaveError($ErrorMessage);
		}
		
		// Return the error filled array.
		public static function GetErrorArray()
		{			
			return Log::$ErrorLog;	
		}
		
		// Return the current time in the Y-m-d H:i:s format.
		private static function SetTime()
		{
			$dateTime = date("Y-m-d H:i:s", time());
			
			return $dateTime;
		}
		
		// Save the error messages to a file.
		private static function SaveError($ErrorMessage)
		{
			$ErrorMessage .= " : " . $_SERVER['REMOTE_ADDR'];
			$handle = fopen(Log::$filename, "a");
			fwrite($handle, $ErrorMessage."\r\n");
			fclose($handle);
		}
		
		// Return array with all the errors from the errorlog.
		public static function GetErrorsFromFile()
		{
			$temp = Array();
			
			$handle = fopen(Log::$filename, "r");
			
			while(!feof($handle))
			{
				$temp[] = fgets($handle);
			}
			
			fclose($handle);
			
			return $temp;	
		}
	}	